package com.kb.design.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kb.design.entity.DesignComment;
import com.kb.design.entity.DesignDictData;
import com.kb.design.entity.DesignDictType;
import com.kb.design.mapper.postgreSQL.DesignCommentMapper;
import com.kb.design.mapper.postgreSQL.DesignDictDataMapper;
import com.kb.design.mapper.postgreSQL.DesignDictMapper;
import com.kb.design.service.DesignCommentService;
import com.kb.design.service.DesignDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;

/**
 * @Auther:chenzx
 * @Date:2023/11/13
 * @Description:
 */
@Service
@DS("slave-1")
public class DesignDictServiceImpl extends ServiceImpl<DesignDictMapper, DesignDictType>  implements DesignDictService {

    @Resource
    private DesignDictMapper designDictMapper;
    @Resource
    private DesignDictDataMapper designDictDataMapper;


    @Override
    public boolean insert(DesignDictType designDictType) {
        //校验唯一 todo

        designDictMapper.insert(designDictType);
        return true;
    }

    @Override
    public boolean insertDictData(DesignDictData designDictData) {
        designDictDataMapper.insert(designDictData);
        return true;
    }

    @Override
    public boolean delDictType(String type) {
        LambdaQueryWrapper<DesignDictType> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(DesignDictType::getDictType,type);
        designDictMapper.delete(queryWrapper);

        LambdaQueryWrapper<DesignDictData> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(DesignDictData::getType,type);
        designDictDataMapper.delete(wrapper);
        return true;
    }

    @Override
    public List<DesignDictData> queryDictByType(DesignDictData designDictData) {
        LambdaQueryWrapper<DesignDictData> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(DesignDictData::getType,designDictData.getType())
                .eq(DesignDictData::getStatus,"0");
        return designDictDataMapper.selectList(queryWrapper);
    }
}
